package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.dao.IUserDao;
import com.example.demo.entity.User;
import com.example.demo.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 用户业务实现类
 */
@Service
@Transactional
public class UserServiceImpl implements IUserService {
    @Resource
    private IUserDao userDao;

    @Override
    @Transactional(readOnly = true)
    public User login(String usrAccount, String usrPassword) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("usr_account", usrAccount);
        User user = userDao.selectOne(queryWrapper);
        //查不到改账户
        if (user == null) return null;
        //账号密码正确
        if (user.getUsrPassword().equals(usrPassword)) return user;
        //密码不正确
        return null;
    }

    @Override
    public boolean register(User user) {
        return userDao.insert(user) == 1;
    }


}
